package com.antler.smt.portal.service.impl;

import com.antler.smt.entity.PurchaserChargeEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.portal.mapper.PurchaserChargeEntityMapper;
import com.antler.smt.request.portal.OrderCommentReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.portal.PurchaserChargeService;
import com.antler.smt.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhangyi
 * @date 2018/4/17 11:26
 */
@Service
public class PurchaserChargeServiceImpl implements PurchaserChargeService {

    @Autowired
    private PurchaserChargeEntityMapper purchaserChargeEntityMapper;

    /**
     *  采购商充值
     *
     * @param memberId
     * @param amount
     * @return
     */
    @Override
    public Result<ResultCodeEnum> purchaserChaser(Long memberId,Long amount) {
        Result result = null;
        //创建采购商充值实体
        PurchaserChargeEntity purchaserChargeEntity = new PurchaserChargeEntity();
        //添加采购商会员id
        purchaserChargeEntity.setMemberId(memberId);
        //添加申请充值金额
        purchaserChargeEntity.setAmmount(amount);
        //创建初始时间
        purchaserChargeEntity.setCreateTime(DateUtil.stampToDate(System.currentTimeMillis()));
        //创建更新时间
        purchaserChargeEntity.setUpdateTime(DateUtil.stampToDate(System.currentTimeMillis()));
        int i = purchaserChargeEntityMapper.insertSelective(purchaserChargeEntity);

        if(0 == i){
            result = new Result(ResultCodeEnum.APPEND_DATA_ERROR);
        }else{
            result = new Result(ResultCodeEnum.OPERATION_SUCCESS);
        }

        return result;
    }
}
